﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace CDSysLDManageProject
{
    public class Log
    {
        private static string logPath = string.Empty;

        public static List<string> Trace = new List<string>();
        public static List<string> MeasureWarning = new List<string>();
        public static List<string> MeasureError = new List<string>();
        public static List<string> SQL = new List<string>();
        public static List<string> SystemError = new List<string>();
        public static List<string> ReciveFromECS = new List<string>();
        public static List<string> SendToECS = new List<string>();
       

         
        /// <summary>
        /// 保存日志的文件夹
        /// </summary>
        /// 
        public static string LogPath
        {
            get
            {
                logPath = AppDomain.CurrentDomain.BaseDirectory+"/log/";

                return logPath;
            }
            set { logPath = value; }
        }

        private static string logFielPrefix = string.Empty;
        /// <summary>
        /// 日志文件前缀
        /// </summary>
        public static string LogFielPrefix
        {
            get { return logFielPrefix; }
            set { logFielPrefix = value; }
        }

        public Log()
        {
            logFielPrefix = "";
        }


        /// <summary>
        /// 写日志
        /// </summary>
        public static void WriteLog(string logFile, string msg)
        {
            try
            {
                string ipath = LogPath + LogFielPrefix + logFile + "/ ";
                if (!Directory.Exists(ipath))
                {
                    Directory.CreateDirectory(ipath);
                }
                System.IO.StreamWriter sw = System.IO.File.AppendText(
                    LogPath + LogFielPrefix + logFile + "/ " +
                    DateTime.Now.ToString("yyyyMMdd") + ".Log"
                    );
                sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss: ") + msg);
                sw.WriteLine();
                sw.Close();
            }
            catch
            { }
        }

        /// <summary>
        /// 写日志
        /// </summary>
        public static void WriteLog(LogFile logFile, string msg)
        {
            WriteLog(logFile.ToString(), msg);
        }
    }


    /// <summary>
    /// 日志类型
    /// </summary>
    public enum LogFile
    {
        Trace,
        MeasureWarning,
        MeasureError,
        SQL,
        SystemError,
        ReciveFromECS,
        SendToECS
    }
}
